<template>
  <div id="app">
    <van-tabbar
      v-model="activeIndex"
      :route="true"
      v-if="this.$route.name != 'VideoInside'"
    >
      <van-tabbar-item
        :to="item.path"
        v-for="(item, index) in navData"
        :key="index"
        @click="changAcive"
      >
        <span>{{
          index == 3 && token != null ? item.title2 : item.title
        }}</span>
        <template #icon>
          <img
            :src="index == activeIndex ? item.icon.active : item.icon.inactive"
          />
        </template>
      </van-tabbar-item>
    </van-tabbar>
    <keep-alive>
      <router-view />
    </keep-alive>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: 1,
      navData: [
        {
          title: "糗事",
          icon: {
            active: require("@/assets/images/home/oL4.png"),
            inactive: require("@/assets/images/home/Lq0.png"),
          },
          path: "/home",
        },
        {
          title: "动态",
          icon: {
            active: require("./assets/images/home/8rR.png"),
            inactive: require("./assets/images/home/8rRr.png"),
          },
          path: "/dynamic",
        },
        {
          title: "小纸条",
          icon: {
            active: require("./assets/images/home/03Z.png"),
            inactive: require("./assets/images/home/UsX.png"),
          },
          path: "/little-page",
        },
        {
          title: "未登录",
          title2: "我",
          icon: {
            active: require("./assets/images/home/8gf.png"),
            inactive: require("./assets/images/home/83s.png"),
          },
          path: "/user",
        },
      ],
      token: null,
    };
  },
  created() {
    this.activeIndex = window.localStorage.getItem("appActiveIndex");
    this.token = window.localStorage.getItem("token");
  },
  watch: {
    $route() {
      this.activeIndex = window.localStorage.getItem("appActiveIndex");
      this.token = window.localStorage.getItem("token");
    },
  },
  methods: {
    changAcive() {
      window.localStorage.setItem("appActiveIndex", this.activeIndex);
    },
  },
};
</script>

<style lang="scss">
.auto-img {
  display: block;
  width: 100%;
}
.van-tabs__wrap--scrollable .van-tab {
  padding: 0 !important;
}
.van-tab {
  margin-right: 20px !important;
}
.van-tabs {
  margin-top: 55px !important;
}
.van-tab--active {
  font-weight: 600 !important;
}
.van-tabs__line {
  bottom: 31px !important;
  height: 6px !important;
}
.van-tab__text {
  z-index: 2 !important;
}
#app {
  letter-spacing: 1px;
}
</style>
